package xin.marcher.wind.migrate.order.mock;

import java.util.Calendar;
import java.util.List;
import java.util.Random;
import java.util.concurrent.atomic.AtomicLong;

/**
 * @Description 订单编码码生成器，生成 32 位数字编码，
 */
public class GenOrderNoUtil {

    static long time = 0;


    private static AtomicLong counter = new AtomicLong(System.currentTimeMillis());

    // 生成十位数字的唯一 ID，并在前面补零
    public static String generateUniqueIdWithPadding() {
        long id = counter.getAndIncrement();
        String uniqueId = String.format("%010d", id); // 前面补零，使长度为十位数
        return uniqueId;
    }


    /**
     * 生成订单单号编码(调用方法)
     *
     * @param userId 网站中该用户唯一 ID 防止重复
     */

    public static String getOrderNo(Long userId) {
        String uid = String.valueOf(userId);
        if (uid.length() == 1) {
            uid = "00" + uid;
        } else if (uid.length() == 2) {
            uid = "0" + uid;
        } else if (uid.length() > 3) {
            uid = uid.substring(uid.length() - 3);
        }
        return generateUniqueIdWithPadding() + uid;
    }


    /**
     * 生成一个编号
     *
     * @return
     */
    public static Long createNo(Integer i) {
        Random random = new Random();
        String methodNo = "" + random.nextInt(i);
        return Long.valueOf(methodNo);
    }

    public static Integer getStatus(List<Integer> list) {
        Random random = new Random();
        int n = random.nextInt(list.size());
        return list.get(n);
    }


    public static java.sql.Date getCreateOrderNoDate() {
        if (time == 0) {
            Calendar cal = Calendar.getInstance();
            cal.set(2024, 0, 1, 8, 0, 0);
            time = cal.getTimeInMillis();
        }
        time += 300;
        return new java.sql.Date(time);
    }

    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            System.out.println(getOrderNo(1L));
        }
    }
}
